//
//  MyMainViewController.swift
//  weibo08
//
//  Created by 陈杰明 on 16/2/27.
//  Copyright © 2016年 JM. All rights reserved.
//

import UIKit

class MyMainViewController: UITabBarController, MyMainTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
//        tabBar.tintColor = UIColor.blackColor()
        
        //自定义tabBar
        //使用kvc
        let mainBar = MyMainTabBar()
        mainBar.composeDelegate = self
        setValue(mainBar, forKey: "tabBar")
        
        addChildViewControllers()
        
    }
    //MARK -实现代理
    func mainTabBarComposeClick() {
        print("实现代理")
    }
    
    ///添加控制器
    func addChildViewControllers() {
        //首页
        let homeVC = MyHomeViewController()
        addChildViewController(homeVC, titleName: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = MyMessageViewController()
        addChildViewController(messageVC, titleName: "消息", imageName: "tabbar_message_center")
        
        //占位控制器
        addChildViewController(UIViewController())
        
        //发现
        let discoverVC = MyDiscoverViewController()
        addChildViewController(discoverVC, titleName: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = MyProfileViewController()
        addChildViewController(profileVC, titleName: "我", imageName: "tabbar_profile")
    
    }
    
    func addChildViewController(controller : UIViewController, titleName : String, imageName : String) {
        //设置titleName
        controller.title = titleName
        //设置图片
        controller.tabBarItem.image = UIImage(named: imageName)
        //设置选中的图片
        let highlightedImageName = imageName + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named:highlightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加到控制器中
        //包装导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
       
    }

   

}
